﻿using System;
using System.Collections.Generic;
using System.Text;
using Hangfire.Server;
using System.Threading;

namespace NFinal.Hangfire.LoggerTest
{
    public class SimpleService
    {
        public void Run(PerformContext context)
        {
            var logger = NFinal.Common.TaskLogger.TaskLoggerFactory.GetTaskLogger(context);
            Inner(logger);
        }
        public void Inner(NFinal.Common.TaskLogger.ITaskLogger logger)
        {
            logger.LogInfo("Start");
            while (true)
            {
                try
                {
                    Console.WriteLine("Hello world!" + DateTime.Now.ToString());
                    logger.CancellationToken.ThrowIfCancellationRequested();
                    Thread.Sleep(1000);
                }
                catch (OperationCanceledException)
                {
                    logger.LogWarn("Cancel");
                    break;
                }
            }
            logger.LogInfo("Finish");
        }
    }
}
